<template>
  <div class="dashboard">
    <!--  用户头像部分  -->
    <div class="user">
      <img class="face" src="~assets/images/head.svg" alt="" />
      <h2 >{{userName}}</h2>
      <p>welcome</p>
    </div>
    <!--  可点击部分  -->
    <div class="links">
      <div class="link">
        <img src="~assets/images/userInfo.svg" alt="">
        <h2>个人信息</h2>
      </div>
      <div class="link">
        <div>
          <img src="~assets/images/encryption.svg" alt=""  @click="encryptDialogVisible = true">
          <h2>加密</h2>
        </div>
      </div>
      <div class="link">
        <img src="~assets/images/decode.svg" @click="decodeDialogVisible=true" alt="">
        <h2>解密</h2>
      </div>
      <div class="link">
        <p @click="logOut">注销</p>
      </div>
    </div>
    <div class="pro">
      <img src="~assets/images/xhu.png" alt="" />
      <h2>西华大学毕业设计</h2>
    </div>

    <el-dialog custom-class="el-dialog-my" v-model="encryptDialogVisible" title="创建任务" width="30%"
        :before-close="handleClose" :destroy-on-close="true" :append-to-body="true">
      <encrypt-dialog @close="handleClose"></encrypt-dialog>
    </el-dialog>

    <el-dialog custom-class="el-dialog-my" v-model="decodeDialogVisible" title="解密文件" width="30%"
               :before-close="handleClose" :destroy-on-close="true" :append-to-body="true">
      <decode-dialog></decode-dialog>
    </el-dialog>

  </div>
</template>

<script>
import EncryptDialog from "components/EncryptDialog";
import DecodeDialog from "components/DecodeDialog";
import http from "@/util/request";

export default {
  name: "DashBoard",
  components: {EncryptDialog, DecodeDialog},
  data() {
    return {
      encryptDialogVisible: false,
      decodeDialogVisible: false
    }
  },
  methods: {
    encrypt(){
      alert("encrypt");
    },
    decode(){
      alert("decode");
    },
    handleClose(done) {
      if(done == 'success'){
        this.encryptDialogVisible = false;
      }else{
        this.$confirm('确认关闭？')
            .then(_ => {
              if(done == 'encryptDialogVisible'){
                this.encryptDialogVisible = false;
              }

              if (done == 'decodeDialogVisible'){
                this.decodeDialogVisible = false;
              }

              if(typeof done == "function"){
                done();
              }
            })
            .catch(_ => {});
      }
    },
    logOut(){
      http.get('/logout').then((response)=>{
        if(response.data == true){
          sessionStorage.removeItem('userName');
          this.$router.push("/");
        }else{
          alert("注销失败，联系管理员！");
        }
      });
    }
  },
  computed: {
    userName(){
      return sessionStorage.getItem('userName');
    }
  }
}
</script>

<style scoped>

.dashboard{
  flex: 0.8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  text-align: center;
  background: linear-gradient(
      to right bottom,
      rgba(255, 255, 255, 0.7),
      rgba(255, 255, 255, 0.3)
  );
  border-radius: 2rem;
}

.user {
  margin: 10%;
  width: 25%;
}

.face {
  width: 100%;
}

.pro {
  background: linear-gradient(to right top, #65dfc9, #6cdbeb);
  border-radius: 1rem;
  color: white;
  padding: 1rem;
  width: 50%;
  display: flex;
  align-items: center;
}

.pro img {
  flex: 1;
  margin-left: 10px;
  width: 50px;
}
.pro h2 {
  flex: 2;
  width: 50%;
  color: white;
  font-weight: 600;
  font-size: 70%;
}

.links {
  display: flex;
  flex-direction: column;
  height: 50%;
  width: 100%;
  align-items:center;
  margin-top: 3%;
}

.link {
  align-items: center;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.link img{
  width: 40px;
  /*鼠标变成小手*/
  cursor:pointer;
}

.link img:hover{
  box-shadow: 2px 2px 2px 2px #909090;
  border-radius: 8px;
}

.link h2{
  font-size: 65%;
  user-select:none;
}

</style>